package bepviet.android.engine;

import java.util.Locale;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class DataFoodAdapter extends DataBaseHelper {

	private static String DB_Name = "Data.sqlite";
	private static String DB_Path = "/data/data/bepviet.android.engine/databases/";
	private Context context;
	public DataFoodAdapter(Context context) {
		super(context, DB_Path, DB_Name);
		this.context = context;
	}
	

	public void Check_CreateDataBase() {
		boolean Exist = CheckDataBase();
		if (Exist) {
			Log.d("TAG", "DataBase already exist!");
		} else {
			CreateData();
		}

	}

	private void CreateData() {
		try{
		SQLiteDatabase db= SQLiteDatabase.openDatabase(DB_Path+"/"+DB_Name,null, SQLiteDatabase.CREATE_IF_NECESSARY);;
		
		 String TABLE_MonAn = "CREATE TABLE MonAn( MaMonAn INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT , "
				+ "TenMonAn VARCHAR, LoaiMonAn VARCHAR, GioiThieu TEXT, NguyenLieuChuanBi TEXT , ThucHien TEXT, HinhAnh Blob)";
		 String TABLE_YeuThich = "CREATE TABLE YeuThich( MaMonAn INTEGER NOT NULL PRIMARY KEY , TenMonAn VARCHAR)";
		db.execSQL(TABLE_MonAn);
		db.execSQL(TABLE_YeuThich);
		}catch(Exception ex){}
	}
	
	public SQLiteDatabase OpenPath(){
		return SQLiteDatabase.openDatabase(DB_Path+"/"+DB_Name, null,SQLiteDatabase.OPEN_READWRITE);
	}
	
	public Long Insert(SQLiteDatabase db,ContentValues values,String TABLE){
		return db.insert(TABLE, null, values);
		
	}
	
	public void Close(SQLiteDatabase db){
		db.close();
	}
	
	public int Delete(SQLiteDatabase db,String value,String TABLE){
		return db.delete(TABLE,"MaMonAn="+ value, null);
		
	}
}
